/*
Copyright 2005-2015 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.weather.api.example;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fricano.java42.base.components.callerid.impl.CallerId;
import com.fricano.java42.base.components.datapointprovider.impl.ProviderConnector;
import com.fricano.java42.base.components.datapointprovider.impl.ProviderFactory;
import com.fricano.java42.weather.api.provider.adapter.Key;
import com.fricano.java42.weather.api.provider.adapter.WeatherProviderInfo;
import com.fricano.java42.weather.api.provider.impl.USGSEarthQuakeProviderInfo;

/**
 *
 * @author CP Fricano
 */
public class USGSEarthQuakeExample {

    public static void main(final String[] args) throws Exception {
        final Object apiKey = ApiKeyStoreUnsecure.class;
        final WeatherProviderInfo info = new USGSEarthQuakeProviderInfo(apiKey);
        info.setQuery("27613");
        info.setOfflineMode(false);
        info.setDevelopmentMode(false);
        final ProviderConnector providerConnector = ProviderFactory.createProvider(info);
        final Map<Object, Object> dataPointMap = providerConnector.connect();
        info.dumpObject(dataPointMap);
        final List<Map<String, Object>> list = info.getMap(Key.LOCATION_FULL);
        for (int x = 0; x != list.size(); x++) {
            final Map<String, Object> properties = list.get(x);
            if (properties != null) {
                CallerId.identifyMessage("WAPI0042I: DataPoint-> WHERE " + properties);
                CallerId.identifyMessage("WAPI0042I: DataPoint-> WHERE " + properties.get("place"));
                final Object time = properties.get("updated");
                final Date date = new Date((Long) time);
                CallerId.identifyMessage("WAPI0042I: DataPoint->  TIME " + date);
                CallerId.identifyMessage("WAPI0042I: DataPoint->   MAG " + properties.get("mag"));
                CallerId.identifyMessage("");
            }
        }

    }

}
